import { UserConfig,loadEnv,ConfigEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
// npm install @types/node --save-dev
import path from "path"
// https://vitejs.dev/config/
export default({mode}:ConfigEnv):UserConfig=>{
  const env = loadEnv(mode, process.cwd());
  return{
    plugins: [
      vue(),
      // AutoImport({
      //   resolvers: [ElementPlusResolver()],
      // }),
      Components({
        resolvers: [
          ElementPlusResolver(),
          AntDesignVueResolver({
            importStyle: false, // css in js
          }),
        ],
      })
    ],
    resolve:{
      alias:{
        "@":path.resolve(__dirname,"./src")
      }
    },
    server: {
      // host: '192.168.100.224',
      port: Number(env.VITE_APP_PORT),
      // open: true, // 运行自动打开浏览器
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: 'http://localhost:8083',
          changeOrigin: true,
          rewrite: path =>
            path.replace(new RegExp('^' + env.VITE_APP_BASE_API), '/')
        }
      }
    },
  }
} 
